import { message } from 'antd';

// const baseURL = 'http://1.15.222.28:4002';
const baseURL = '/api'

export default function request(url, options = {}) {
    // console.log('哈哈哈哈哈哈哈哈哈哈哈哈哈哈',options);
    options.headers = {
        token: localStorage.token,
        Authorization:localStorage.token,
    }
    if (options.method && options.method.toUpperCase() !== 'GET') {
        options.body = JSON.stringify(options.body)
        options.headers['Content-Type'] = 'application/json';
    }
    return fetch(baseURL + url, options).then(response => {
        // console.log('-----', response);
        switch (response.status) {
            case 200:
                return response.json();
        }
    }).then(res => {
        // console.log('+++++++', res);
        if (res.code == 1) {
            return res;
        } else {
            res.msg && message.error(res.msg)
            return Promise.reject(res)
        }
    })
}